/*
  Name: DeadProxyEventQueue.cpp
  Copyright:
  Author: Carl Chatfield
  Date: 18/01/08 17:32
  Description: Event Queue for Client Event Handler
*/

#include "DeadProxyClient.h"
#include "DeadProxyClientEventHandler.h"
#include <wx/arrimpl.cpp> //this is needed for wxArrays, i dont know why lol
WX_DEFINE_OBJARRAY(ArrayOfEvents);

EventQueue::EventQueue()
{
    Queue = new ArrayOfEvents;
    mutex = new wxMutex();
    mutex->Unlock();
}

void EventQueue::AddEvent(ClientEvent * evt)
{
    mutex->Lock();
    Queue->Add(evt);
    mutex->Unlock();
}

void EventQueue::InsertEvent(ClientEvent * evt)
{
    mutex->Lock();
    Queue->Insert(evt, 0);
    mutex->Unlock();
}

ClientEvent * EventQueue::GetEvent()
{
    ClientEvent * evt;
    mutex->Lock();
    evt = Queue->Detach(0);
    mutex->Unlock();
    return evt;
}

int EventQueue::GetCount()
{
    int len;
    mutex->Lock();
    len = Queue->GetCount();
    mutex->Unlock();
    return len;
}

EventQueue::~EventQueue()
{
    mutex->Lock();
    delete Queue;
    mutex->Unlock();
    delete mutex;
}
